//
//  CZMainViewController.swift
//  新浪微博
//
//  Created by apple on 15/11/23.
//  Copyright © 2015年 0523. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {
    func composeClick(){
        print(__FUNCTION__)
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tabBar.tintColor=UIColor.orangeColor()
        let homevc=CZHomeViewController()
        addChildViewController(homevc, title: "首页", imagename:"tabbar_home" )
        let messagevc=CZMessageViewController()
        addChildViewController(messagevc, title: "消息", imagename: "tabbar_message_center")
        addChildViewController(UIViewController())
        let discover=CZDiscoverViewControlle()
        addChildViewController(discover, title: "发现", imagename: "tabbar_discover")
        let profilevc=CZProfileViewController()
        addChildViewController(profilevc, title: "我", imagename: "tabbar_profile")
        
    }
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        let width=tabBar.bounds.size.width/5
        let frame=CGRect(x:2 * width-5 , y: 0, width: width+10, height:tabBar.bounds.size.height )
        composebutton.frame=frame
    }
    private func addChildViewController(controller:UIViewController,title:String,imagename:String) {
    controller.title=title
        controller.tabBarItem.image=UIImage(named:imagename )
        let hightedimagename=imagename+"_highlighted"
        let hightimage=UIImage(named: hightedimagename)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
      addChildViewController(UINavigationController(rootViewController: controller))
    }
    lazy var composebutton: UIButton = {
        let button=UIButton()
        button.setBackgroundImage(UIImage(named:"tabbar_compose_button" ), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        self.tabBar.addSubview(button)
//        button.addTarget(self, action: "com", forControlEvents:UIControlEvents.TouchUpInside )
        
        button.addTarget(self, action: "composeClick", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
